package leetcode91_100;

import outoforder.leetcode.TreeNode;

/**
 * @author shhjiang_001
 * @create 2020-07-08 19:17
 */

// 验证二叉搜索树
public class Solution98 {
    public boolean isValidBST(TreeNode root) {
        boolean flag = isValidBST(root,null,null);
        return flag;
    }

    private boolean isValidBST(TreeNode root, TreeNode min, TreeNode max) {
        if (root == null) return true;
        if (min != null && root.val <= min.val) return false;
        if (max != null && root.val >= max.val) return false;
        return isValidBST(root.left,min,root)&&isValidBST(root.right,root,max);
    }
}
